package com.mooc.lib_video.ui.svga

import android.app.Activity
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.listener.OnItemClickListener
import java.util.ArrayList

class SVGAFragment : Fragment(),OnItemClickListener {
    private lateinit var recyclerView:RecyclerView
    private lateinit var listener : OnSVGAClickListener

    override fun onAttach(activity: Activity) {
        super.onAttach(activity)
        listener = activity as OnSVGAClickListener
    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        recyclerView = RecyclerView(requireContext())
        val lp = ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT)
        recyclerView.layoutParams = lp
        val manager = GridLayoutManager(context,4)
        manager.orientation = GridLayoutManager.VERTICAL
        recyclerView.layoutManager = manager
        var list = ArrayList<String>()
        while (list.size < 30)
            list.add("item")
        val adapter:SVGAAdapter = SVGAAdapter()
        adapter.setOnItemClickListener(this)
        recyclerView.adapter = adapter
        adapter.setNewInstance(list)
        return recyclerView
    }

     interface OnSVGAClickListener{
        fun onSvgAClick(name : String)
    }

    override fun onItemClick(adapter: BaseQuickAdapter<*, *>, view: View, position: Int) {
          listener.onSvgAClick("angel.svga")
    }
}